/*
 * JsonRpcServletContext
 *
 * Copyright Aldrin Edison Baroi 2006
 *
 * Aldrin Edison Baroi <aldrin91011@yahoo.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */
package org.charless.spring.jsonrpc;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.Map;
import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.FilterRegistration.Dynamic;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import javax.servlet.descriptor.JspConfigDescriptor;

/**
 * JSON-RPC servlet is not configured using web.xml and ServletContext provided
 * by the container is immutable. JsonRpcServletContext delegates all calls to
 * ServletContext provided by the container, except "getInitParameterNames()"
 * and "getInitParameter()" calls. It delegates these call to
 * JsonRpcServletConfig.
 *
 *
 * @author Aldrin E Baroi
 *
 */
public class JsonRpcServletContext implements ServletContext
{
    private final ServletContext servletContext;
    private final JsonRpcServletConfig jsonRpcServletConfig;

    /**
     *
     */
    public JsonRpcServletContext(ServletContext servletContext)
    {
        super();
        this.servletContext = servletContext;
        this.jsonRpcServletConfig = new JsonRpcServletConfig(this,
                servletContext);
    }

    public JsonRpcServletConfig getJsonRpcServletConfg()
    {
        return this.jsonRpcServletConfig;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getContext(java.lang.String)
     */
    @Override
    public ServletContext getContext(String context)
    {
        return this.servletContext.getContext(context);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getMajorVersion()
     */
    @Override
    public int getMajorVersion()
    {
        return this.servletContext.getMajorVersion();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getMinorVersion()
     */
    @Override
    public int getMinorVersion()
    {
        return this.servletContext.getMinorVersion();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
     */
    public String getMimeType(String arg0)
    {
        return this.servletContext.getMimeType(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
     */
    @Override
    public Set<String> getResourcePaths(String arg0)
    {
        return this.servletContext.getResourcePaths(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getResource(java.lang.String)
     */
    @Override
    public URL getResource(String arg0) throws MalformedURLException
    {
        return this.servletContext.getResource(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
     */
    @Override
    public InputStream getResourceAsStream(String arg0)
    {
        return this.servletContext.getResourceAsStream(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
     */
    @Override
    public RequestDispatcher getRequestDispatcher(String arg0)
    {
        return this.servletContext.getRequestDispatcher(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
     */
    @Override
    public RequestDispatcher getNamedDispatcher(String arg0)
    {
        return this.servletContext.getNamedDispatcher(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getServlet(java.lang.String)
     */
    /**
     * @deprecated
     */
    @Override
    public Servlet getServlet(String arg0) throws ServletException
    {
        return this.servletContext.getServlet(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getServlets()
     */
    /**
     * @deprecated
     */
    @Override
    public Enumeration<Servlet> getServlets()
    {
        return this.servletContext.getServlets();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getServletNames()
     */
    /**
     * @deprecated
     */
    @Override
    public Enumeration<String> getServletNames()
    {
        return this.servletContext.getServletNames();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#log(java.lang.String)
     */
    @Override
    public void log(String arg0)
    {
        this.servletContext.log(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#log(java.lang.Exception,
     *      java.lang.String)
     */
    /**
     * @deprecated
     */
    @Override
    public void log(Exception arg0, String arg1)
    {
        this.servletContext.log(arg0, arg1);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#log(java.lang.String,
     *      java.lang.Throwable)
     */
    @Override
    public void log(String arg0, Throwable arg1)
    {
        this.servletContext.log(arg0, arg1);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
     */
    @Override
    public String getRealPath(String arg0)
    {
        return this.servletContext.getRealPath(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getServerInfo()
     */
    @Override
    public String getServerInfo()
    {
        return this.servletContext.getServerInfo();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
     */
    @Override
    public String getInitParameter(String arg0)
    {
        return this.jsonRpcServletConfig.getInitParameter(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getInitParameterNames()
     */
    @Override
    public Enumeration<String> getInitParameterNames()
    {
        return this.jsonRpcServletConfig.getInitParameterNames();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
     */
    @Override
    public Object getAttribute(String arg0)
    {
        return this.servletContext.getAttribute(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getAttributeNames()
     */
    @Override
    public Enumeration<String> getAttributeNames()
    {
        //return (Enumeration<?>)this.servletContext.getAttributeNames();
        return this.servletContext.getAttributeNames();
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#setAttribute(java.lang.String,
     *      java.lang.Object)
     */
    @Override
    public void setAttribute(String arg0, Object arg1)
    {
        this.servletContext.setAttribute(arg0, arg1);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
     */
    @Override
    public void removeAttribute(String arg0)
    {
        this.servletContext.removeAttribute(arg0);
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.servlet.ServletContext#getServletContextName()
     */
    @Override
    public String getServletContextName()
    {
        return this.servletContext.getServletContextName();
    }

    @Override
    public Dynamic addFilter( String arg0, String arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Dynamic addFilter( String arg0, Filter arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Dynamic addFilter( String arg0, Class<? extends Filter> arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void addListener( String arg0 )
    {
        // TODO Auto-generated method stub
    }

    @Override
    public <T extends EventListener> void addListener( T arg0 )
    {
        // TODO Auto-generated method stub
    }

    @Override
    public void addListener( Class<? extends EventListener> arg0 )
    {
        // TODO Auto-generated method stub
    }

    @Override
    public javax.servlet.ServletRegistration.Dynamic addServlet( String arg0,
            String arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public javax.servlet.ServletRegistration.Dynamic addServlet( String arg0,
            Servlet arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public javax.servlet.ServletRegistration.Dynamic addServlet( String arg0,
            Class<? extends Servlet> arg1 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T extends Filter> T createFilter( Class<T> arg0 )
            throws ServletException
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T extends EventListener> T createListener( Class<T> arg0 )
            throws ServletException
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T extends Servlet> T createServlet( Class<T> arg0 )
            throws ServletException
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void declareRoles( String... arg0 )
    {
        // TODO Auto-generated method stub
    }

    @Override
    public ClassLoader getClassLoader()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getContextPath()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public int getEffectiveMajorVersion()
    {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getEffectiveMinorVersion()
    {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public FilterRegistration getFilterRegistration( String arg0 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, ? extends FilterRegistration> getFilterRegistrations()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public JspConfigDescriptor getJspConfigDescriptor()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public ServletRegistration getServletRegistration( String arg0 )
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, ? extends ServletRegistration> getServletRegistrations()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public SessionCookieConfig getSessionCookieConfig()
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean setInitParameter( String arg0, String arg1 )
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void setSessionTrackingModes( Set<SessionTrackingMode> arg0 )
    {
        // TODO Auto-generated method stub
    }
}
